﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CNCSoft.EData;
using Common;

namespace CNCSoft.ErpApps.TMS.longGiaoVu
{
    public partial class frmAllKhoaHocDoiDuyet : Form
    {
        private SqlConnection conn = new SqlConnection(GlobalVariable.WSInfo.ConnectionString);
        private DataSet ds = new DataSet();
        private string _userid = GlobalVariable.WSInfo.UserID;

        public frmAllKhoaHocDoiDuyet()
        {
            InitializeComponent();
        }

        private void frmAllKhoaHocDoiDuyet_Load(object sender, EventArgs e)
        {
            if (_userid == "tuptc")
            {
                btnDuyet.Enabled = true;
            }
            else
            {
                btnDuyet.Enabled = false;
            }
            LoadData();
        }

        private void btnDuyet_Click(object sender, EventArgs e)
        {
            CapNhat();
            LoadData();
        }

        private void btnBoQua_Click(object sender, EventArgs e)
        {
            BoQua();
            LoadData();
        }

        #region "Coding"
        private void LoadData()
        {
            LoadAllKhoaHocDoiDuyet();
            gridControl_Data.DataSource = ds.Tables["TableAllKhoaHocDoiDuyet"];
        }

        private void LoadAllKhoaHocDoiDuyet()
        {
            try
            {
                if (ds.Tables["TableAllKhoaHocDoiDuyet"] != null)
                    ds.Tables["TableAllKhoaHocDoiDuyet"].Clear();
                string sql = @"usp_AllKhoaHocDoiDuyet";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                da.Fill(ds, "TableAllKhoaHocDoiDuyet");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void CapNhat()
        {
            try
            {
                string sql = @"SELECT * FROM DM_KHOAHOC";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                DataHelper.buildDataCommands(ref da);
                da.Update(ds, "TableAllKhoaHocDoiDuyet");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void BoQua()
        {
            ds.RejectChanges();
        }
        #endregion
    }
}
